/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gmail.avereshchaga.validation;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author <a href="mailto:avereshchaga@gmail.com">Vereshchaga Alexey</a>
 */
public class FieldVerifier extends InputVerifier {

    @Override
    public boolean verify(JComponent input) {
        String stringFromField = ((JTextField) input).getText().trim();
        return (!stringFromField.equals(""));
    }

    @Override
    public boolean shouldYieldFocus(JComponent input) {
        boolean inputOK = verify(input);
        if (inputOK) {
            return true;
        } else {
            JOptionPane.showMessageDialog(null, "Field can't be empty", "Warning", 2);
            return false;
        }
    }
}
